package org.zoomdev.zoom.dao;

import org.zoomdev.zoom.dao.driver.SqlDriver;

import javax.sql.DataSource;
import java.util.Iterator;
import java.util.List;

/**
 * dao类
 */
public interface Dao {


    DataSource dataSource();

    Ar<Record> raw(String table);

    Ar<Record> raw();

    Ar<Record> ar(String table);

    /**
     * 绑定实体类与表    Map.class 有效 ,Map的衍生类有效,如TreeMap等
     *
     * @param classOfT
     * @param table
     * @param <T>
     * @return
     */
    <T> Ar<T> ar(Class<T> classOfT, String table);

    <T> Ar<T> ar(Class<T> entityClass);

    <T> Ar<T> ar(Entity<T> entity);


    /**
     * 创建一个新的entity builder
     *
     * @return
     */
    EntityBuilder entityBuilder();

    DatabaseConfig config();


    /**
     * 获取entity
     *
     * @param entityClass
     * @return
     */
    Entity entity(Class<?> entityClass);

    /**
     * 获取entity
     *
     * @param entityClass
     * @param tableName
     * @return
     */
    Entity entity(Class<?> entityClass, String tableName);


    SqlDriver sqlDriver();

    String productName();

    <T> T execute(ConnectionExecutor executor);


    int update(String sql, Object... args);

    int updates(String sql, Iterator<Object[]> args);

    <T> T get(Class<T> classOfT, String sql, Object... args);

    <T> List<T> query(Class<T> classOfT, String sql, Object... args);

    /**
     * 是否输出sql
     *
     * @param output
     */
    void setOutput(boolean output);
}
